package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeTypePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.model.dto.response.ServeTypeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 服务表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-16
 */
@RestController
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 服务相关接口")
public class ServeController {
    @Resource
    private IServeService serveService;
    @GetMapping("/page")
    @ApiOperation("区域服务类型分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO dto) {
        return serveService.page(dto);
    }
    @ApiOperation("区域服务新增")
    @PostMapping("/batch")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtoList", value = "服务列表", required = true, dataTypeClass = List.class)
    })
    public void addBatch(@RequestBody List<ServeUpsertReqDTO> dtoList){
        serveService.addBatch(dtoList);
    }
    @ApiOperation("区域服务上架")
    @PutMapping("/onSale/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    })
    public void onSale(@PathVariable("id") Long id){
        serveService.onSale(id);
    }


    @PutMapping("/{id}")
    @ApiOperation("区域服务价格修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)
    })
    public void update(@PathVariable("id") Long id,
                       @RequestParam("price") BigDecimal price) {
        serveService.updatePrice(id, price);
    }

    /**
     * 删除区域服务
     * @param id 服务id
     */
    @ApiOperation("区域服务删除")
    @DeleteMapping("/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    })
    public void delete(@PathVariable("id") Long id){
        serveService.delete(id);
    }

    /**
     * 下架区域服务
     * @param id
     */
    @ApiOperation("区域服务下架")
    @PutMapping("/offSale/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    })
    public void offSale(@PathVariable("id") Long id){
        serveService.offSale(id);
    }

    /**
     * 设置服务为热门服务
     * @param id
     */
    @ApiOperation("设置服务为热门服务")
    @PutMapping("/onHot/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    })
    public void onHot(@PathVariable("id") Long id){
        serveService.onHot(id);
    }


    /**
     * 取消热门服务
     * @param id
     */
    @ApiOperation("取消热门服务")
    @PutMapping("/offHot/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    })
    public void offHot(@PathVariable("id") Long id){
        serveService.offHot(id);
    }














}
